using System;

namespace Scenario.Modules.FormHelper
{
	/// <summary>
	/// Summary description for XMLReturnValue.
	/// </summary>
	public class XMLReturnValue: bOSdotNET.XML.Data.XMLObject
	{
		public const string MAIN_NODE				= "ReturnValue";
		public const string TYPE_ATTRIBUTE			= "Type";
		public const string TOTRANSFORM_ATTRIBUTE	= "ToTransform";

		// General flags values
		public const string XSLT_VALUE		="XSLT";
		public const string XPATH_VALUE		="XPATH";
		public string sType;
		public string sValue;
		public string sToTransform;

		public XMLReturnValue()
		{
			this.Init();
		}

		public XMLReturnValue(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		override public void Init()
		{
			sType= string.Empty;
			sValue= string.Empty;
			sToTransform= string.Empty;
		}

		/** PROPERTIES **/


		public string Type 
		{
			get { return sType; }
			set { sType = value; }
		}

		public string Value 
		{
			get { return sValue; }
			set { sValue = value; }
		}

		public string ToTransform 
		{
			get { return sToTransform; }
			set { sToTransform = value; }
		}

		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;

			/** find the attributes situated on the root tag **/
			for ( int i=0; i<node2Parse.Attributes.Count;i++)
			{
				node = node2Parse.Attributes.Item(i);

				switch ( node.Name )
				{
					case XMLReturnValue.TYPE_ATTRIBUTE:
						sType = node.InnerText;
						break;
					case XMLReturnValue.TOTRANSFORM_ATTRIBUTE:
						sToTransform= node.InnerText;
						break;
				}
			}

			sValue = node2Parse.InnerText;
			
		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode xmlNode = new bOSdotNET.XML.XMLNode(XMLReturnValue.MAIN_NODE,sValue);
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute ( XMLReturnValue.TYPE_ATTRIBUTE, sType) );
			
			return xmlNode;
		}
	}
}
